package com.example.mybackend.controller;

import com.example.mybackend.entity.travelogue;
import com.example.mybackend.service.travelogueService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("travelogue")
@CrossOrigin
public class travelogueController {
    @Autowired
    private travelogueService travelogueService;

    @GetMapping("all")
    public List<travelogue> getAll() {
        return travelogueService.queryAll();
    }

    @GetMapping("deleted")
    public List<travelogue> getDeleted() {
        return travelogueService.queryDeleted();
    }

    @GetMapping("pending")
    public List<travelogue> getStatus0() {
        return travelogueService.queryStatus0();
    }

    @GetMapping("pass")
    public List<travelogue> getStatus1() {
        return travelogueService.queryStatus1();
    }

    @GetMapping("reject")
    public List<travelogue> getStatus2() {
        return travelogueService.queryStatus2();
    }

    @PutMapping("delete/{id}")
    public Integer delete(@PathVariable Integer id){
        return travelogueService.Delete(id);
    }
    @PutMapping("recover/{id}")
    public Integer recover(@PathVariable Integer id){
        return travelogueService.Recover(id);
    }
    @PutMapping("approve/{id}")
    public Integer pass(@PathVariable Integer id){
        return travelogueService.Pass(id);
    }
    @PutMapping("refuse")
    public Integer reject(@RequestBody travelogue Travelogue){
        return travelogueService.Reject(Travelogue);
    }

    @GetMapping("content")
    public List<travelogue> getByContent(@RequestParam String content){
        return travelogueService.queryContentLike(content);
    }

    @GetMapping("username")
    public List<travelogue> getByusername(@RequestParam String username){
        return travelogueService.queryUserLike(username);
    }
}
